<template>
  <!-- 编辑组合名称Dialog -->
  <vc-dialog
    ref="editNameDialogRef"
    v-model="show"
    width="25%"
    height="30vh"
    title="修改名称"
    title-align="left"
    show-cancel-button
    show-confirm-button
    @open="handleEditNameDialogOpen(group.name)"
    @confirm="handleEditNameDialogConfirm(group.id, emit, editNameDialogRef)"
  >
    <div class="form">
      <span class="label">组合名称</span>
      <input v-model="editGroupName" class="input" type="text" placeholder="请输入组合名称" />
    </div>
    <div class="tips">
      <span class="label"></span>
      <span class="recommend">
        <span class="recommend-label">推荐名称</span>
        <span class="recommend-item" v-for="item in recommendItems" :key="item" @click="setGroupName(item)">{{ item }}</span>
      </span>
    </div>
  </vc-dialog>
</template>

<script setup lang="ts">
import { useEditNameDialog } from '../useDialog';
import { type IGroup } from '../apis';

interface Props {
  modelValue: boolean;
  group: IGroup;
}
const { modelValue } = defineProps<Props>();

const emit = defineEmits<{
  (e: 'update:modelValue', val: boolean): void;
  (e: 'change'): void;
}>();

/** 自定义v-model */
const show = computed({
  get() {
    return modelValue;
  },
  set(value) {
    emit('update:modelValue', value);
  }
});

const editNameDialogRef = ref();

const { editGroupName, recommendItems, handleEditNameDialogOpen, setGroupName, handleEditNameDialogConfirm } = useEditNameDialog();
</script>

<style lang="scss" scoped>
.vc-dialog {
  .form,
  .tips {
    padding: 0 16px;
    display: flex;
    align-items: center;
    .label {
      width: 80px;
      font-size: 14px;
      color: #666;
    }
    .input {
      flex: 1;
      padding: 10px 16px;
      height: 40px;
      font-size: 14px;
      color: #333;
      border: 1px solid #e3e3e3;
      border-radius: 4px;
      outline: none;
      &:focus {
        border: 1px solid #008ef4;
      }
    }
    .recommend {
      flex: 1;
      display: inline-flex;
      align-items: center;
      gap: 12px;
      font-size: 12px;
      .recommend-label {
        color: #333;
      }
      .recommend-item {
        color: #008ef4;
        cursor: pointer;
      }
    }
  }
  .form {
    margin-top: 16px;
  }
  .tips {
    margin-top: 10px;
  }
}
</style>
